import pymysql

# 创建数据库连接
db = pymysql.connect(
    host = "localhost",
    port = 3306,
    user = "root",
    password = "hhp20040512",
    charset = "utf8",
    database = "crawlerDemo"
)

# 获取操作游标，即操作数据库的一个对象
cursor = db.cursor()
# 使用该对象进行操作
cursor.execute("select * from student")
print(cursor)
# fetchone()用来获取一条数据，字符串
data=cursor.fetchone()
# # print("当前数据库版本%s" %data)
# print(data)
# fetchall() 方法用来获取所有数据，获取的结果用元组(tuple)保存
data = cursor.fetchall()
print(data)

# 关闭游标和连接
cursor.close()
db.close()